package com.indobrains.uud1945;

import android.content.Context;
import android.database.Cursor;
import android.support.v4.widget.SimpleCursorAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.indobrains.uud1945.database.DatabaseAdapter;

public class SearchAdapter extends SimpleCursorAdapter {
	private static final String TAG = "Chapter Adapter";
	private int layout;
	private Context mContext;
	private DatabaseAdapter db;
	public SearchAdapter(Context context, int layout,Cursor c, String[] from, int[] to){
		super(context,layout,c,from,to);
		this.layout=layout;
		this.mContext=context;
		db=new DatabaseAdapter(mContext);
		db.Open();
	}
	public String getChapter(long chapter_id){
		Cursor cursor=db.fetchChapter(chapter_id);
		cursor.moveToFirst();
		return cursor.getString(cursor.getColumnIndex(db.CHAPTER_DESC));
	}
	@Override
	public void bindView(View v, Context context, Cursor c) {
		// TODO Auto-generated method stub
		//super.bindView(v, context, c);
		String s_title=c.getString(c.getColumnIndex(db.CLAUSE_TITLE));
		String s_bullet=c.getString(c.getColumnIndex(db.CONTENT_BULLET));
		String s_chapter=c.getString(c.getColumnIndex("chapter_name"));
		String s_chapter_desc=c.getString(c.getColumnIndex("chapter_description"));
		String s_content=c.getString(c.getColumnIndex(db.CONTENT_CONTENT));
		String s_amandemen=c.getString(c.getColumnIndex(db.AMANDEMEN_DESC));
		String s_older=c.getString(c.getColumnIndex(db.CONTENT_OLDER));
		TextView title=(TextView)v.findViewById(R.id.search_title);
		TextView chapter=(TextView)v.findViewById(R.id.search_chapter);
		TextView content=(TextView)v.findViewById(R.id.search_content);
		TextView amandemen=(TextView)v.findViewById(R.id.search_amandemen);
		TextView older=(TextView)v.findViewById(R.id.search_older);
		title.setText(s_title+" "+s_bullet);
		chapter.setText(s_chapter+" "+s_chapter_desc);
		content.setText(s_content);
		amandemen.setText(s_amandemen);
		older.setText(s_older);
		
	}
	@Override
	public View newView(Context context, Cursor cursor, ViewGroup parent) {
		// TODO Auto-generated method stub
		final LayoutInflater inflater = LayoutInflater.from(context);
		View v = inflater.inflate(layout, parent, false);
		return v;
	}

}
